package com.example.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springboot.common.PageHelper;
import com.example.springboot.entity.CheckException;
import com.example.springboot.entity.CheckRoom;
import com.example.springboot.entity.Student;
import com.example.springboot.mapper.CheckExceptionMapper;
import com.example.springboot.mapper.CheckRoomMapper;
import com.example.springboot.service.CheckExceptionService;
import com.example.springboot.service.CheckRoomService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CheckExceptionServiceImpl  extends ServiceImpl<CheckExceptionMapper, CheckException> implements CheckExceptionService {
    @Resource
    private CheckExceptionMapper checkExceptionMapper;


    @Override
    public int addCheckException(CheckException checkException) {
        return checkExceptionMapper.insert(checkException);
    }

    @Override
    public PageInfo find(Integer pageNum, Integer pageSize, String search) {

        List<CheckException> checkRoomList = checkExceptionMapper.findsql(search, pageNum, pageSize);


        PageInfo page= PageHelper.pageHelper(checkRoomList,pageNum,pageSize);

        return page;
    }

    @Override
    public int updateStatu(Integer id) {
        return checkExceptionMapper.updateStatu(id);
    }

    /**
     * 主页顶部：学生统计
     */
    @Override
    public int exceptionNum() {
        QueryWrapper<CheckException> qw = new QueryWrapper<>();
        qw.isNotNull("id");
        int exceptionNum = Math.toIntExact(checkExceptionMapper.selectCount(qw));
        return exceptionNum;
    }
}
